import { _decorator, Button, Label, size, Sprite, UITransform } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import { Ab_ClientAPI_bA } from '../../api/client.api';
import Ab_GameDC_bA from '../../manager/data.game.center';
import Ab_GameAssets_bA from '../../manager/game.assets';
import { Ab_Float_bA } from '../page/float';
import type { Ab_Popup_bA } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('Ab_Resurgence_bA')
export class Ab_Resurgence_bA extends Ab_BasePopUp_bA<typeof Ab_Popup_bA, boolean> {
	protected Ab_default_return_bA: null;

	private ui_container: UITransform;

	protected Ab_initAfterOnLoad_bA(){
		this.ui_container = this.node.getChildByName('container').getComponent(UITransform);
		this.Ab_renderLocalUI_bA();
	}

	protected Ab__click_event__bA: { [name: string]: (this: Ab_Resurgence_bA, button: Button) => void; } = {
		close(btn){
			btn.interactable = false;
			this.Ab_exit_bA(false).then(()=>btn.interactable = true);
		},
		diamond(btn){
			btn.interactable = false;
			if(Ab_GameDC_bA.Ab_User_bA.Ab_diamond_bA >= 100) this.Ab_exit_bA(true).then(()=>btn.interactable = true);
			else{
				Ab_Float_bA.Ab_Hint_bA(Ab_GameAssets_bA.Ab_getLangText_bA(65));
				btn.interactable = true;
			}
		},
	 	async video(btn){
			btn.interactable = false;
			Ab_ClientAPI_bA.Ab_AD_bA('incentive');
			await this.Ab_exit_bA(true);
			btn.interactable = true;
		}
	}

	private async Ab_exit_bA(confirm: boolean){
		await Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.ui_container.node);
		this.Ab_close_bA(confirm);
	}

	public Ab_onShow_bA(){
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.ui_container.node);
	}

	private Ab_renderLocalUI_bA(){
		let ui_title = this.ui_container.node.getChildByName('title').getComponent(UITransform);
		let title_size = size(
			this.ui_container.width,
			ui_title.height
		);

		let sframe = Ab_GameAssets_bA.Ab_getLangTexture_bA(4);

		let scale = Math.min(title_size.width/sframe.originalSize.width, title_size.height/sframe.originalSize.height);

		ui_title.getComponent(Sprite).spriteFrame = sframe;

		ui_title.setContentSize(
			sframe.originalSize.width*scale,
			sframe.originalSize.height*scale
		);

		this.ui_container.node.getChildByName('lbl-video').getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(34);
		this.ui_container.node.getChildByName('lbl-diamond').getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(33, 100);
		this.ui_container.node.getComponentsInChildren(Label).find(lb=>lb.node.name=='close').string = Ab_GameAssets_bA.Ab_getLangText_bA(35);
	}
}

